

<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
  <meta charset="utf-8">
  
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  
  <title>federatedml.evaluation.test.evaluation_run_test &mdash; FATE 1.0 documentation</title>
  

  
  
  
  

  
  <script type="text/javascript" src="../../../../_static/js/modernizr.min.js"></script>
  
    
      <script type="text/javascript" id="documentation_options" data-url_root="../../../../" src="../../../../_static/documentation_options.js"></script>
        <script type="text/javascript" src="../../../../_static/jquery.js"></script>
        <script type="text/javascript" src="../../../../_static/underscore.js"></script>
        <script type="text/javascript" src="../../../../_static/doctools.js"></script>
        <script type="text/javascript" src="../../../../_static/language_data.js"></script>
    
    <script type="text/javascript" src="../../../../_static/js/theme.js"></script>

    

  
  <link rel="stylesheet" href="../../../../_static/css/theme.css" type="text/css" />
  <link rel="stylesheet" href="../../../../_static/pygments.css" type="text/css" />
    <link rel="index" title="Index" href="../../../../genindex.html" />
    <link rel="search" title="Search" href="../../../../search.html" /> 
</head>

<body class="wy-body-for-nav">

   
  <div class="wy-grid-for-nav">
    
    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
      <div class="wy-side-scroll">
        <div class="wy-side-nav-search" >
          

          
            <a href="../../../../index.html" class="icon icon-home"> FATE
          

          
          </a>

          
            
            
          

          
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="../../../../search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>

          
        </div>

        <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
          
            
            
              
            
            
              <!-- Local TOC -->
              <div class="local-toc"></div>
            
          
        </div>
      </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">

      
      <nav class="wy-nav-top" aria-label="top navigation">
        
          <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
          <a href="../../../../index.html">FATE</a>
        
      </nav>


      <div class="wy-nav-content">
        
        <div class="rst-content">
        
          















<div role="navigation" aria-label="breadcrumbs navigation">

  <ul class="wy-breadcrumbs">
    
      <li><a href="../../../../index.html">Docs</a> &raquo;</li>
        
          <li><a href="../../../index.html">Module code</a> &raquo;</li>
        
      <li>federatedml.evaluation.test.evaluation_run_test</li>
    
    
      <li class="wy-breadcrumbs-aside">
        
      </li>
    
  </ul>

  
  <hr/>
</div>
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
           <div itemprop="articleBody">
            
  <h1>Source code for federatedml.evaluation.test.evaluation_run_test</h1><div class="highlight"><pre>
<span></span><span class="ch">#!/usr/bin/env python</span>
<span class="c1"># -*- coding: utf-8 -*-</span>

<span class="c1">#</span>
<span class="c1">#  Copyright 2019 The FATE Authors. All Rights Reserved.</span>
<span class="c1">#</span>
<span class="c1">#  Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);</span>
<span class="c1">#  you may not use this file except in compliance with the License.</span>
<span class="c1">#  You may obtain a copy of the License at</span>
<span class="c1">#</span>
<span class="c1">#      http://www.apache.org/licenses/LICENSE-2.0</span>
<span class="c1">#</span>
<span class="c1">#  Unless required by applicable law or agreed to in writing, software</span>
<span class="c1">#  distributed under the License is distributed on an &quot;AS IS&quot; BASIS,</span>
<span class="c1">#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.</span>
<span class="c1">#  See the License for the specific language governing permissions and</span>
<span class="c1">#  limitations under the License.</span>
<span class="kn">import</span> <span class="nn">unittest</span>

<span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
<span class="kn">from</span> <span class="nn">sklearn.metrics</span> <span class="k">import</span> <span class="n">roc_curve</span><span class="p">,</span> <span class="n">precision_score</span>
<span class="kn">from</span> <span class="nn">sklearn.metrics</span> <span class="k">import</span> <span class="n">recall_score</span>

<span class="kn">from</span> <span class="nn">federatedml.evaluation.evaluation</span> <span class="k">import</span> <span class="n">Evaluation</span>


<div class="viewcode-block" id="TestEvaluationBinary"><a class="viewcode-back" href="../../../../federatedml.evaluation.test.html#federatedml.evaluation.test.evaluation_run_test.TestEvaluationBinary">[docs]</a><span class="k">class</span> <span class="nc">TestEvaluationBinary</span><span class="p">(</span><span class="n">unittest</span><span class="o">.</span><span class="n">TestCase</span><span class="p">):</span>
<div class="viewcode-block" id="TestEvaluationBinary.setUp"><a class="viewcode-back" href="../../../../federatedml.evaluation.test.html#federatedml.evaluation.test.evaluation_run_test.TestEvaluationBinary.setUp">[docs]</a>    <span class="k">def</span> <span class="nf">setUp</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">data_num</span> <span class="o">=</span> <span class="mi">50</span>
        <span class="n">final_result</span> <span class="o">=</span> <span class="p">[]</span>

        <span class="c1"># for i in range(self.data_num):</span>
        <span class="c1">#     tmp = [np.random.choice([0, 1]), np.random.random(), np.random.choice([0, 1]), np.random.choice([0, 1]),</span>
        <span class="c1">#            &quot;train&quot;]</span>
        <span class="c1">#     tmp_pair = (str(i), tmp)</span>
        <span class="c1">#     final_result.append(tmp_pair)</span>
        <span class="c1">#</span>
        <span class="c1"># self.table = eggroll.parallelize(final_result,</span>
        <span class="c1">#                                  include_key=True,</span>
        <span class="c1">#                                  partition=10)</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">model_name</span> <span class="o">=</span> <span class="s1">&#39;Evaluation&#39;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">args</span> <span class="o">=</span> <span class="p">{</span><span class="s2">&quot;data&quot;</span><span class="p">:</span> <span class="p">{</span><span class="bp">self</span><span class="o">.</span><span class="n">model_name</span><span class="p">:</span> <span class="p">{</span><span class="s2">&quot;data&quot;</span><span class="p">:</span> <span class="kc">None</span><span class="p">}}}</span></div>

    <span class="k">def</span> <span class="nf">_make_param_dict</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="n">component_param</span> <span class="o">=</span> <span class="p">{</span>
            <span class="s2">&quot;EvaluateParam&quot;</span><span class="p">:</span> <span class="p">{</span>
                <span class="s2">&quot;eval_type&quot;</span><span class="p">:</span> <span class="s2">&quot;binary&quot;</span><span class="p">,</span>
                <span class="s2">&quot;pos_label&quot;</span><span class="p">:</span> <span class="mi">1</span>
            <span class="p">}</span>
        <span class="p">}</span>

        <span class="k">return</span> <span class="n">component_param</span>

<div class="viewcode-block" id="TestEvaluationBinary.test_evaluation"><a class="viewcode-back" href="../../../../federatedml.evaluation.test.html#federatedml.evaluation.test.evaluation_run_test.TestEvaluationBinary.test_evaluation">[docs]</a>    <span class="k">def</span> <span class="nf">test_evaluation</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">eval_obj</span> <span class="o">=</span> <span class="n">Evaluation</span><span class="p">()</span>
        <span class="n">component_param</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_make_param_dict</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">eval_obj</span><span class="o">.</span><span class="n">run</span><span class="p">(</span><span class="n">component_param</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">args</span><span class="p">)</span>

        <span class="c1">### start test</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">auc_test</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">ks_test</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">lift_test</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">precision_test</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">recall_test</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">accuracy_test</span><span class="p">()</span></div>

<div class="viewcode-block" id="TestEvaluationBinary.assertFloatEqual"><a class="viewcode-back" href="../../../../federatedml.evaluation.test.html#federatedml.evaluation.test.evaluation_run_test.TestEvaluationBinary.assertFloatEqual">[docs]</a>    <span class="k">def</span> <span class="nf">assertFloatEqual</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">op1</span><span class="p">,</span> <span class="n">op2</span><span class="p">):</span>
        <span class="n">diff</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">abs</span><span class="p">(</span><span class="n">op1</span> <span class="o">-</span> <span class="n">op2</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">assertLess</span><span class="p">(</span><span class="n">diff</span><span class="p">,</span> <span class="mf">1e-6</span><span class="p">)</span></div>

<div class="viewcode-block" id="TestEvaluationBinary.auc_test"><a class="viewcode-back" href="../../../../federatedml.evaluation.test.html#federatedml.evaluation.test.evaluation_run_test.TestEvaluationBinary.auc_test">[docs]</a>    <span class="k">def</span> <span class="nf">auc_test</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="n">y_true</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">])</span>
        <span class="n">y_predict</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="mf">0.1</span><span class="p">,</span> <span class="mf">0.4</span><span class="p">,</span> <span class="mf">0.35</span><span class="p">,</span> <span class="mf">0.8</span><span class="p">])</span>
        <span class="n">ground_true_auc</span> <span class="o">=</span> <span class="mf">0.75</span>

        <span class="n">auc</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">eval_obj</span><span class="o">.</span><span class="n">auc</span><span class="p">(</span><span class="n">y_true</span><span class="p">,</span> <span class="n">y_predict</span><span class="p">)</span>
        <span class="n">auc</span> <span class="o">=</span> <span class="nb">round</span><span class="p">(</span><span class="n">auc</span><span class="p">,</span> <span class="mi">2</span><span class="p">)</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">assertFloatEqual</span><span class="p">(</span><span class="n">auc</span><span class="p">,</span> <span class="n">ground_true_auc</span><span class="p">)</span></div>

<div class="viewcode-block" id="TestEvaluationBinary.ks_test"><a class="viewcode-back" href="../../../../federatedml.evaluation.test.html#federatedml.evaluation.test.evaluation_run_test.TestEvaluationBinary.ks_test">[docs]</a>    <span class="k">def</span> <span class="nf">ks_test</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="n">y_true</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">])</span>
        <span class="n">y_predict</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span>
            <span class="p">[</span><span class="mf">0.42</span><span class="p">,</span> <span class="mf">0.73</span><span class="p">,</span> <span class="mf">0.55</span><span class="p">,</span> <span class="mf">0.37</span><span class="p">,</span> <span class="mf">0.57</span><span class="p">,</span> <span class="mf">0.70</span><span class="p">,</span> <span class="mf">0.25</span><span class="p">,</span> <span class="mf">0.23</span><span class="p">,</span> <span class="mf">0.46</span><span class="p">,</span> <span class="mf">0.62</span><span class="p">,</span> <span class="mf">0.76</span><span class="p">,</span> <span class="mf">0.46</span><span class="p">,</span> <span class="mf">0.55</span><span class="p">,</span> <span class="mf">0.56</span><span class="p">,</span> <span class="mf">0.56</span><span class="p">,</span> <span class="mf">0.38</span><span class="p">,</span> <span class="mf">0.37</span><span class="p">,</span> <span class="mf">0.73</span><span class="p">,</span>
             <span class="mf">0.77</span><span class="p">,</span> <span class="mf">0.21</span><span class="p">,</span> <span class="mf">0.39</span><span class="p">])</span>
        <span class="n">ground_true_ks</span> <span class="o">=</span> <span class="mf">0.75</span>

        <span class="n">sk_fpr</span><span class="p">,</span> <span class="n">sk_tpr</span> <span class="p">,</span><span class="n">sk_threshold</span> <span class="o">=</span> <span class="n">roc_curve</span><span class="p">(</span><span class="n">y_true</span><span class="p">,</span> <span class="n">y_predict</span><span class="p">,</span> <span class="n">drop_intermediate</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>

        <span class="n">ks</span><span class="p">,</span> <span class="n">fpr</span><span class="p">,</span> <span class="n">tpr</span><span class="p">,</span> <span class="n">threshold</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">eval_obj</span><span class="o">.</span><span class="n">ks</span><span class="p">(</span><span class="n">y_true</span><span class="p">,</span> <span class="n">y_predict</span><span class="p">)</span>
        <span class="n">ks</span> <span class="o">=</span> <span class="nb">round</span><span class="p">(</span><span class="n">ks</span><span class="p">,</span> <span class="mi">2</span><span class="p">)</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">assertFloatEqual</span><span class="p">(</span><span class="n">ks</span><span class="p">,</span> <span class="n">ground_true_ks</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">assertListEqual</span><span class="p">(</span><span class="n">fpr</span><span class="p">,</span> <span class="nb">list</span><span class="p">(</span><span class="n">sk_fpr</span><span class="p">))</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">assertListEqual</span><span class="p">(</span><span class="n">tpr</span><span class="p">,</span> <span class="nb">list</span><span class="p">(</span><span class="n">sk_tpr</span><span class="p">))</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">assertListEqual</span><span class="p">(</span><span class="n">threshold</span><span class="p">,</span> <span class="nb">list</span><span class="p">(</span><span class="n">sk_threshold</span><span class="p">))</span></div>

<div class="viewcode-block" id="TestEvaluationBinary.lift_test"><a class="viewcode-back" href="../../../../federatedml.evaluation.test.html#federatedml.evaluation.test.evaluation_run_test.TestEvaluationBinary.lift_test">[docs]</a>    <span class="k">def</span> <span class="nf">lift_test</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="n">y_true</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">])</span>
        <span class="n">y_predict</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="mf">0.57</span><span class="p">,</span> <span class="mf">0.70</span><span class="p">,</span> <span class="mf">0.25</span><span class="p">,</span> <span class="mf">0.30</span><span class="p">,</span> <span class="mf">0.46</span><span class="p">,</span> <span class="mf">0.62</span><span class="p">,</span> <span class="mf">0.76</span><span class="p">,</span> <span class="mf">0.46</span><span class="p">,</span> <span class="mf">0.35</span><span class="p">,</span> <span class="mf">0.56</span><span class="p">])</span>
        <span class="n">dict_score</span> <span class="o">=</span> <span class="p">{</span><span class="s2">&quot;0&quot;</span><span class="p">:</span> <span class="p">{</span><span class="mi">0</span><span class="p">:</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">:</span> <span class="mi">1</span><span class="p">},</span> <span class="s2">&quot;0.4&quot;</span><span class="p">:</span> <span class="p">{</span><span class="mi">0</span><span class="p">:</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">1</span><span class="p">:</span> <span class="mf">1.43</span><span class="p">},</span> <span class="s2">&quot;0.6&quot;</span><span class="p">:</span> <span class="p">{</span><span class="mi">0</span><span class="p">:</span> <span class="mf">1.43</span><span class="p">,</span> <span class="mi">1</span><span class="p">:</span> <span class="mi">2</span><span class="p">}}</span>

        <span class="n">split_thresholds</span> <span class="o">=</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mf">0.4</span><span class="p">,</span> <span class="mf">0.6</span><span class="p">]</span>

        <span class="n">lifts</span><span class="p">,</span> <span class="n">thresholds</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">eval_obj</span><span class="o">.</span><span class="n">lift</span><span class="p">(</span><span class="n">y_true</span><span class="p">,</span> <span class="n">y_predict</span><span class="p">,</span> <span class="n">thresholds</span><span class="o">=</span><span class="n">split_thresholds</span><span class="p">)</span>
        <span class="n">fix_lifts</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="k">for</span> <span class="n">lift</span> <span class="ow">in</span> <span class="n">lifts</span><span class="p">:</span>
            <span class="n">fix_lift</span> <span class="o">=</span> <span class="p">[</span><span class="nb">round</span><span class="p">(</span><span class="n">pos</span><span class="p">,</span> <span class="mi">2</span><span class="p">)</span> <span class="k">for</span> <span class="n">pos</span> <span class="ow">in</span> <span class="n">lift</span><span class="p">]</span>
            <span class="n">fix_lifts</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">fix_lift</span><span class="p">)</span>

        <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">split_thresholds</span><span class="p">)):</span>
            <span class="n">score_0</span> <span class="o">=</span> <span class="n">dict_score</span><span class="p">[</span><span class="nb">str</span><span class="p">(</span><span class="n">split_thresholds</span><span class="p">[</span><span class="n">i</span><span class="p">])][</span><span class="mi">0</span><span class="p">]</span>
            <span class="n">score_1</span> <span class="o">=</span> <span class="n">dict_score</span><span class="p">[</span><span class="nb">str</span><span class="p">(</span><span class="n">split_thresholds</span><span class="p">[</span><span class="n">i</span><span class="p">])][</span><span class="mi">1</span><span class="p">]</span>

            <span class="n">pos_lift</span> <span class="o">=</span> <span class="n">fix_lifts</span><span class="p">[</span><span class="n">i</span><span class="p">]</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">assertEqual</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">pos_lift</span><span class="p">),</span> <span class="mi">2</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">assertFloatEqual</span><span class="p">(</span><span class="n">score_0</span><span class="p">,</span> <span class="n">pos_lift</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">assertFloatEqual</span><span class="p">(</span><span class="n">score_1</span><span class="p">,</span> <span class="n">pos_lift</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">assertListEqual</span><span class="p">(</span><span class="n">split_thresholds</span><span class="p">,</span> <span class="n">thresholds</span><span class="p">)</span></div>

<div class="viewcode-block" id="TestEvaluationBinary.precision_test"><a class="viewcode-back" href="../../../../federatedml.evaluation.test.html#federatedml.evaluation.test.evaluation_run_test.TestEvaluationBinary.precision_test">[docs]</a>    <span class="k">def</span> <span class="nf">precision_test</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="n">y_true</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">])</span>
        <span class="n">y_predict</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="mf">0.57</span><span class="p">,</span> <span class="mf">0.70</span><span class="p">,</span> <span class="mf">0.25</span><span class="p">,</span> <span class="mf">0.30</span><span class="p">,</span> <span class="mf">0.46</span><span class="p">,</span> <span class="mf">0.62</span><span class="p">,</span> <span class="mf">0.76</span><span class="p">,</span> <span class="mf">0.46</span><span class="p">,</span> <span class="mf">0.35</span><span class="p">,</span> <span class="mf">0.56</span><span class="p">])</span>
        <span class="n">dict_score</span> <span class="o">=</span> <span class="p">{</span><span class="s2">&quot;0.4&quot;</span><span class="p">:</span> <span class="p">{</span><span class="mi">0</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">:</span> <span class="mf">0.71</span><span class="p">},</span> <span class="s2">&quot;0.6&quot;</span><span class="p">:</span> <span class="p">{</span><span class="mi">0</span><span class="p">:</span> <span class="mf">0.71</span><span class="p">,</span> <span class="mi">1</span><span class="p">:</span> <span class="mi">1</span><span class="p">}}</span>

        <span class="n">split_thresholds</span> <span class="o">=</span> <span class="p">[</span><span class="mf">0.4</span><span class="p">,</span> <span class="mf">0.6</span><span class="p">]</span>

        <span class="n">prec_values</span><span class="p">,</span> <span class="n">thresholds</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">eval_obj</span><span class="o">.</span><span class="n">precision</span><span class="p">(</span><span class="n">y_true</span><span class="p">,</span> <span class="n">y_predict</span><span class="p">,</span> <span class="n">thresholds</span><span class="o">=</span><span class="n">split_thresholds</span><span class="p">)</span>
        <span class="n">fix_prec_values</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="k">for</span> <span class="n">prec_value</span> <span class="ow">in</span> <span class="n">prec_values</span><span class="p">:</span>
            <span class="n">fix_prec_value</span> <span class="o">=</span> <span class="p">[</span><span class="nb">round</span><span class="p">(</span><span class="n">pos</span><span class="p">,</span> <span class="mi">2</span><span class="p">)</span> <span class="k">for</span> <span class="n">pos</span> <span class="ow">in</span> <span class="n">prec_value</span><span class="p">]</span>
            <span class="n">fix_prec_values</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">fix_prec_value</span><span class="p">)</span>

        <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">split_thresholds</span><span class="p">)):</span>
            <span class="n">score_0</span> <span class="o">=</span> <span class="n">dict_score</span><span class="p">[</span><span class="nb">str</span><span class="p">(</span><span class="n">split_thresholds</span><span class="p">[</span><span class="n">i</span><span class="p">])][</span><span class="mi">0</span><span class="p">]</span>
            <span class="n">score_1</span> <span class="o">=</span> <span class="n">dict_score</span><span class="p">[</span><span class="nb">str</span><span class="p">(</span><span class="n">split_thresholds</span><span class="p">[</span><span class="n">i</span><span class="p">])][</span><span class="mi">1</span><span class="p">]</span>

            <span class="n">pos_prec_value</span> <span class="o">=</span> <span class="n">fix_prec_values</span><span class="p">[</span><span class="n">i</span><span class="p">]</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">assertEqual</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">pos_prec_value</span><span class="p">),</span> <span class="mi">2</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">assertFloatEqual</span><span class="p">(</span><span class="n">score_0</span><span class="p">,</span> <span class="n">pos_prec_value</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">assertFloatEqual</span><span class="p">(</span><span class="n">score_1</span><span class="p">,</span> <span class="n">pos_prec_value</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">assertListEqual</span><span class="p">(</span><span class="n">thresholds</span><span class="p">,</span> <span class="n">split_thresholds</span><span class="p">)</span></div>

<div class="viewcode-block" id="TestEvaluationBinary.recall_test"><a class="viewcode-back" href="../../../../federatedml.evaluation.test.html#federatedml.evaluation.test.evaluation_run_test.TestEvaluationBinary.recall_test">[docs]</a>    <span class="k">def</span> <span class="nf">recall_test</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="n">y_true</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">])</span>
        <span class="n">y_predict</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="mf">0.57</span><span class="p">,</span> <span class="mf">0.70</span><span class="p">,</span> <span class="mf">0.25</span><span class="p">,</span> <span class="mf">0.31</span><span class="p">,</span> <span class="mf">0.46</span><span class="p">,</span> <span class="mf">0.62</span><span class="p">,</span> <span class="mf">0.76</span><span class="p">,</span> <span class="mf">0.46</span><span class="p">,</span> <span class="mf">0.35</span><span class="p">,</span> <span class="mf">0.56</span><span class="p">])</span>
        <span class="n">dict_score</span> <span class="o">=</span> <span class="p">{</span><span class="s2">&quot;0.3&quot;</span><span class="p">:</span> <span class="p">{</span><span class="mi">0</span><span class="p">:</span> <span class="mf">0.2</span><span class="p">,</span> <span class="mi">1</span><span class="p">:</span> <span class="mi">1</span><span class="p">},</span> <span class="s2">&quot;0.4&quot;</span><span class="p">:</span> <span class="p">{</span><span class="mi">0</span><span class="p">:</span> <span class="mf">0.6</span><span class="p">,</span> <span class="mi">1</span><span class="p">:</span> <span class="mi">1</span><span class="p">}}</span>

        <span class="n">split_thresholds</span> <span class="o">=</span> <span class="p">[</span><span class="mf">0.3</span><span class="p">,</span> <span class="mf">0.4</span><span class="p">]</span>

        <span class="n">recalls</span><span class="p">,</span> <span class="n">thresholds</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">eval_obj</span><span class="o">.</span><span class="n">recall</span><span class="p">(</span><span class="n">y_true</span><span class="p">,</span> <span class="n">y_predict</span><span class="p">,</span> <span class="n">thresholds</span><span class="o">=</span><span class="n">split_thresholds</span><span class="p">)</span>
        <span class="n">round_recalls</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="k">for</span> <span class="n">recall</span> <span class="ow">in</span> <span class="n">recalls</span><span class="p">:</span>
            <span class="n">round_recall</span> <span class="o">=</span> <span class="p">[</span><span class="nb">round</span><span class="p">(</span><span class="n">pos</span><span class="p">,</span> <span class="mi">2</span><span class="p">)</span> <span class="k">for</span> <span class="n">pos</span> <span class="ow">in</span> <span class="n">recall</span><span class="p">]</span>
            <span class="n">round_recalls</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">round_recall</span><span class="p">)</span>

        <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">split_thresholds</span><span class="p">)):</span>
            <span class="n">score_0</span> <span class="o">=</span> <span class="n">dict_score</span><span class="p">[</span><span class="nb">str</span><span class="p">(</span><span class="n">split_thresholds</span><span class="p">[</span><span class="n">i</span><span class="p">])][</span><span class="mi">0</span><span class="p">]</span>
            <span class="n">score_1</span> <span class="o">=</span> <span class="n">dict_score</span><span class="p">[</span><span class="nb">str</span><span class="p">(</span><span class="n">split_thresholds</span><span class="p">[</span><span class="n">i</span><span class="p">])][</span><span class="mi">1</span><span class="p">]</span>

            <span class="n">pos_recall</span> <span class="o">=</span> <span class="n">round_recalls</span><span class="p">[</span><span class="n">i</span><span class="p">]</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">assertEqual</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">pos_recall</span><span class="p">),</span> <span class="mi">2</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">assertFloatEqual</span><span class="p">(</span><span class="n">score_0</span><span class="p">,</span> <span class="n">pos_recall</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">assertFloatEqual</span><span class="p">(</span><span class="n">score_1</span><span class="p">,</span> <span class="n">pos_recall</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">assertListEqual</span><span class="p">(</span><span class="n">thresholds</span><span class="p">,</span> <span class="n">split_thresholds</span><span class="p">)</span></div>

<div class="viewcode-block" id="TestEvaluationBinary.accuracy_test"><a class="viewcode-back" href="../../../../federatedml.evaluation.test.html#federatedml.evaluation.test.evaluation_run_test.TestEvaluationBinary.accuracy_test">[docs]</a>    <span class="k">def</span> <span class="nf">accuracy_test</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="n">y_true</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">])</span>
        <span class="n">y_predict</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="mf">0.57</span><span class="p">,</span> <span class="mf">0.70</span><span class="p">,</span> <span class="mf">0.25</span><span class="p">,</span> <span class="mf">0.31</span><span class="p">,</span> <span class="mf">0.46</span><span class="p">,</span> <span class="mf">0.62</span><span class="p">,</span> <span class="mf">0.76</span><span class="p">,</span> <span class="mf">0.46</span><span class="p">,</span> <span class="mf">0.35</span><span class="p">,</span> <span class="mf">0.56</span><span class="p">])</span>
        <span class="n">gt_score</span> <span class="o">=</span> <span class="p">{</span><span class="s2">&quot;0.3&quot;</span><span class="p">:</span> <span class="mf">0.6</span><span class="p">,</span> <span class="s2">&quot;0.5&quot;</span><span class="p">:</span> <span class="mf">1.0</span><span class="p">,</span> <span class="s2">&quot;0.7&quot;</span><span class="p">:</span> <span class="mf">0.7</span><span class="p">}</span>

        <span class="n">split_thresholds</span> <span class="o">=</span> <span class="p">[</span><span class="mf">0.3</span><span class="p">,</span> <span class="mf">0.5</span><span class="p">,</span> <span class="mf">0.7</span><span class="p">]</span>

        <span class="n">acc</span><span class="p">,</span> <span class="n">thresholds</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">eval_obj</span><span class="o">.</span><span class="n">accuracy</span><span class="p">(</span><span class="n">y_true</span><span class="p">,</span> <span class="n">y_predict</span><span class="p">,</span> <span class="n">thresholds</span><span class="o">=</span><span class="n">split_thresholds</span><span class="p">)</span>
        <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">split_thresholds</span><span class="p">)):</span>
            <span class="n">score</span> <span class="o">=</span> <span class="n">gt_score</span><span class="p">[</span><span class="nb">str</span><span class="p">(</span><span class="n">split_thresholds</span><span class="p">[</span><span class="n">i</span><span class="p">])]</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">assertFloatEqual</span><span class="p">(</span><span class="n">score</span><span class="p">,</span> <span class="n">acc</span><span class="p">[</span><span class="n">i</span><span class="p">])</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">assertListEqual</span><span class="p">(</span><span class="n">thresholds</span><span class="p">,</span> <span class="n">split_thresholds</span><span class="p">)</span></div>

<div class="viewcode-block" id="TestEvaluationBinary.tearDown"><a class="viewcode-back" href="../../../../federatedml.evaluation.test.html#federatedml.evaluation.test.evaluation_run_test.TestEvaluationBinary.tearDown">[docs]</a>    <span class="k">def</span> <span class="nf">tearDown</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="c1"># self.table.destroy()</span>
        <span class="k">pass</span></div></div>

<div class="viewcode-block" id="TestEvaluationMulti"><a class="viewcode-back" href="../../../../federatedml.evaluation.test.html#federatedml.evaluation.test.evaluation_run_test.TestEvaluationMulti">[docs]</a><span class="k">class</span> <span class="nc">TestEvaluationMulti</span><span class="p">(</span><span class="n">unittest</span><span class="o">.</span><span class="n">TestCase</span><span class="p">):</span>
<div class="viewcode-block" id="TestEvaluationMulti.setUp"><a class="viewcode-back" href="../../../../federatedml.evaluation.test.html#federatedml.evaluation.test.evaluation_run_test.TestEvaluationMulti.setUp">[docs]</a>    <span class="k">def</span> <span class="nf">setUp</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">data_num</span> <span class="o">=</span> <span class="mi">50</span>
        <span class="c1"># final_result = []</span>

        <span class="c1"># for i in range(self.data_num):</span>
        <span class="c1">#     tmp = [np.random.choice([0, 1]), np.random.random(), np.random.choice([0, 1]), np.random.choice([0, 1]),</span>
        <span class="c1">#            &quot;train&quot;]</span>
        <span class="c1">#     tmp_pair = (str(i), tmp)</span>
        <span class="c1">#     final_result.append(tmp_pair)</span>
        <span class="c1">#</span>
        <span class="c1"># self.table = eggroll.parallelize(final_result,</span>
        <span class="c1">#                                  include_key=True,</span>
        <span class="c1">#                                  partition=10)</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">model_name</span> <span class="o">=</span> <span class="s1">&#39;Evaluation&#39;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">args</span> <span class="o">=</span> <span class="p">{</span><span class="s2">&quot;data&quot;</span><span class="p">:</span> <span class="p">{</span><span class="bp">self</span><span class="o">.</span><span class="n">model_name</span><span class="p">:</span> <span class="p">{</span><span class="s2">&quot;data&quot;</span><span class="p">:</span> <span class="kc">None</span><span class="p">}}}</span></div>

    <span class="k">def</span> <span class="nf">_make_param_dict</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="n">component_param</span> <span class="o">=</span> <span class="p">{</span>
            <span class="s2">&quot;EvaluateParam&quot;</span><span class="p">:</span> <span class="p">{</span>
                <span class="s2">&quot;eval_type&quot;</span><span class="p">:</span> <span class="s2">&quot;multi&quot;</span><span class="p">,</span>
                <span class="s2">&quot;pos_label&quot;</span><span class="p">:</span> <span class="mi">1</span>
            <span class="p">}</span>
        <span class="p">}</span>

        <span class="k">return</span> <span class="n">component_param</span>

<div class="viewcode-block" id="TestEvaluationMulti.test_evaluation"><a class="viewcode-back" href="../../../../federatedml.evaluation.test.html#federatedml.evaluation.test.evaluation_run_test.TestEvaluationMulti.test_evaluation">[docs]</a>    <span class="k">def</span> <span class="nf">test_evaluation</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">eval_obj</span> <span class="o">=</span> <span class="n">Evaluation</span><span class="p">()</span>
        <span class="n">component_param</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_make_param_dict</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">eval_obj</span><span class="o">.</span><span class="n">run</span><span class="p">(</span><span class="n">component_param</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">args</span><span class="p">)</span>

        <span class="c1">### start test</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">accuracy_test</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">precision_test</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">recall_test</span><span class="p">()</span></div>

<div class="viewcode-block" id="TestEvaluationMulti.assertFloatEqual"><a class="viewcode-back" href="../../../../federatedml.evaluation.test.html#federatedml.evaluation.test.evaluation_run_test.TestEvaluationMulti.assertFloatEqual">[docs]</a>    <span class="k">def</span> <span class="nf">assertFloatEqual</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">op1</span><span class="p">,</span> <span class="n">op2</span><span class="p">):</span>
        <span class="n">diff</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">abs</span><span class="p">(</span><span class="n">op1</span> <span class="o">-</span> <span class="n">op2</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">assertLess</span><span class="p">(</span><span class="n">diff</span><span class="p">,</span> <span class="mf">1e-6</span><span class="p">)</span></div>

<div class="viewcode-block" id="TestEvaluationMulti.accuracy_test"><a class="viewcode-back" href="../../../../federatedml.evaluation.test.html#federatedml.evaluation.test.evaluation_run_test.TestEvaluationMulti.accuracy_test">[docs]</a>    <span class="k">def</span> <span class="nf">accuracy_test</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="n">y_true</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="mi">4</span><span class="p">])</span>
        <span class="n">y_predict</span> <span class="o">=</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="mi">4</span><span class="p">]</span>
        <span class="n">gt_score</span> <span class="o">=</span> <span class="mf">0.6</span>
        <span class="n">gt_number</span> <span class="o">=</span> <span class="mi">12</span>

        <span class="n">acc</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">eval_obj</span><span class="o">.</span><span class="n">accuracy</span><span class="p">(</span><span class="n">y_true</span><span class="p">,</span> <span class="n">y_predict</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">assertFloatEqual</span><span class="p">(</span><span class="n">gt_score</span><span class="p">,</span> <span class="n">acc</span><span class="p">)</span>
        <span class="n">acc_number</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">eval_obj</span><span class="o">.</span><span class="n">accuracy</span><span class="p">(</span><span class="n">y_true</span><span class="p">,</span> <span class="n">y_predict</span><span class="p">,</span> <span class="n">normalize</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">assertEqual</span><span class="p">(</span><span class="n">acc_number</span><span class="p">,</span> <span class="n">gt_number</span><span class="p">)</span></div>

<div class="viewcode-block" id="TestEvaluationMulti.recall_test"><a class="viewcode-back" href="../../../../federatedml.evaluation.test.html#federatedml.evaluation.test.evaluation_run_test.TestEvaluationMulti.recall_test">[docs]</a>    <span class="k">def</span> <span class="nf">recall_test</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="n">y_true</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="mi">5</span><span class="p">,</span> <span class="mi">5</span><span class="p">,</span> <span class="mi">5</span><span class="p">,</span> <span class="mi">5</span><span class="p">,</span> <span class="mi">5</span><span class="p">])</span>
        <span class="n">y_predict</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="mi">6</span><span class="p">,</span> <span class="mi">6</span><span class="p">,</span> <span class="mi">6</span><span class="p">,</span> <span class="mi">6</span><span class="p">,</span> <span class="mi">6</span><span class="p">])</span>
        <span class="n">sk_recall</span> <span class="o">=</span> <span class="n">recall_score</span><span class="p">(</span><span class="n">y_true</span><span class="p">,</span> <span class="n">y_predict</span><span class="p">,</span> <span class="n">average</span><span class="o">=</span><span class="kc">None</span><span class="p">)</span>
        <span class="n">gt_labels</span> <span class="o">=</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span><span class="mi">2</span><span class="p">,</span><span class="mi">3</span><span class="p">,</span><span class="mi">4</span><span class="p">,</span><span class="mi">5</span><span class="p">,</span><span class="mi">6</span><span class="p">]</span>

        <span class="n">recalls</span><span class="p">,</span> <span class="n">all_labels</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">eval_obj</span><span class="o">.</span><span class="n">recall</span><span class="p">(</span><span class="n">y_true</span><span class="p">,</span> <span class="n">y_predict</span><span class="p">)</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">assertListEqual</span><span class="p">(</span><span class="nb">list</span><span class="p">(</span><span class="n">recalls</span><span class="p">),</span> <span class="nb">list</span><span class="p">(</span><span class="n">sk_recall</span><span class="p">))</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">assertListEqual</span><span class="p">(</span><span class="n">all_labels</span><span class="p">,</span> <span class="n">gt_labels</span><span class="p">)</span></div>

<div class="viewcode-block" id="TestEvaluationMulti.precision_test"><a class="viewcode-back" href="../../../../federatedml.evaluation.test.html#federatedml.evaluation.test.evaluation_run_test.TestEvaluationMulti.precision_test">[docs]</a>    <span class="k">def</span> <span class="nf">precision_test</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="n">y_true</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="mi">5</span><span class="p">,</span> <span class="mi">5</span><span class="p">,</span> <span class="mi">5</span><span class="p">,</span> <span class="mi">5</span><span class="p">,</span> <span class="mi">5</span><span class="p">])</span>
        <span class="n">y_predict</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="mi">6</span><span class="p">,</span> <span class="mi">6</span><span class="p">,</span> <span class="mi">6</span><span class="p">,</span> <span class="mi">6</span><span class="p">,</span> <span class="mi">6</span><span class="p">])</span>
        <span class="n">sk_precision</span> <span class="o">=</span> <span class="n">precision_score</span><span class="p">(</span><span class="n">y_true</span><span class="p">,</span> <span class="n">y_predict</span><span class="p">,</span> <span class="n">average</span><span class="o">=</span><span class="kc">None</span><span class="p">)</span>
        <span class="n">gt_labels</span> <span class="o">=</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="mi">5</span><span class="p">,</span> <span class="mi">6</span><span class="p">]</span>

        <span class="n">precision</span><span class="p">,</span> <span class="n">all_labels</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">eval_obj</span><span class="o">.</span><span class="n">precision</span><span class="p">(</span><span class="n">y_true</span><span class="p">,</span> <span class="n">y_predict</span><span class="p">)</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">assertListEqual</span><span class="p">(</span><span class="nb">list</span><span class="p">(</span><span class="n">precision</span><span class="p">),</span> <span class="nb">list</span><span class="p">(</span><span class="n">sk_precision</span><span class="p">))</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">assertListEqual</span><span class="p">(</span><span class="n">all_labels</span><span class="p">,</span> <span class="n">gt_labels</span><span class="p">)</span></div>

<div class="viewcode-block" id="TestEvaluationMulti.tearDown"><a class="viewcode-back" href="../../../../federatedml.evaluation.test.html#federatedml.evaluation.test.evaluation_run_test.TestEvaluationMulti.tearDown">[docs]</a>    <span class="k">def</span> <span class="nf">tearDown</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="c1"># self.table.destroy()</span>
        <span class="k">pass</span></div></div>

<div class="viewcode-block" id="TestEvaluationRegression"><a class="viewcode-back" href="../../../../federatedml.evaluation.test.html#federatedml.evaluation.test.evaluation_run_test.TestEvaluationRegression">[docs]</a><span class="k">class</span> <span class="nc">TestEvaluationRegression</span><span class="p">(</span><span class="n">unittest</span><span class="o">.</span><span class="n">TestCase</span><span class="p">):</span>
<div class="viewcode-block" id="TestEvaluationRegression.setUp"><a class="viewcode-back" href="../../../../federatedml.evaluation.test.html#federatedml.evaluation.test.evaluation_run_test.TestEvaluationRegression.setUp">[docs]</a>    <span class="k">def</span> <span class="nf">setUp</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">data_num</span> <span class="o">=</span> <span class="mi">50</span>
        <span class="c1"># final_result = []</span>

        <span class="c1"># for i in range(self.data_num):</span>
        <span class="c1">#     tmp = [np.random.choice([0, 1]), np.random.random(), np.random.choice([0, 1]), np.random.choice([0, 1]),</span>
        <span class="c1">#            &quot;train&quot;]</span>
        <span class="c1">#     tmp_pair = (str(i), tmp)</span>
        <span class="c1">#     final_result.append(tmp_pair)</span>
        <span class="c1">#</span>
        <span class="c1"># self.table = eggroll.parallelize(final_result,</span>
        <span class="c1">#                                  include_key=True,</span>
        <span class="c1">#                                  partition=10)</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">model_name</span> <span class="o">=</span> <span class="s1">&#39;Evaluation&#39;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">args</span> <span class="o">=</span> <span class="p">{</span><span class="s2">&quot;data&quot;</span><span class="p">:</span> <span class="p">{</span><span class="bp">self</span><span class="o">.</span><span class="n">model_name</span><span class="p">:</span> <span class="p">{</span><span class="s2">&quot;data&quot;</span><span class="p">:</span> <span class="kc">None</span><span class="p">}}}</span></div>

    <span class="k">def</span> <span class="nf">_make_param_dict</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="n">component_param</span> <span class="o">=</span> <span class="p">{</span>
            <span class="s2">&quot;EvaluateParam&quot;</span><span class="p">:</span> <span class="p">{</span>
                <span class="s2">&quot;eval_type&quot;</span><span class="p">:</span> <span class="s2">&quot;regression&quot;</span><span class="p">,</span>
                <span class="s2">&quot;pos_label&quot;</span><span class="p">:</span> <span class="mi">1</span>
            <span class="p">}</span>
        <span class="p">}</span>

        <span class="k">return</span> <span class="n">component_param</span>

<div class="viewcode-block" id="TestEvaluationRegression.test_evaluation"><a class="viewcode-back" href="../../../../federatedml.evaluation.test.html#federatedml.evaluation.test.evaluation_run_test.TestEvaluationRegression.test_evaluation">[docs]</a>    <span class="k">def</span> <span class="nf">test_evaluation</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">eval_obj</span> <span class="o">=</span> <span class="n">Evaluation</span><span class="p">()</span>
        <span class="n">component_param</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_make_param_dict</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">eval_obj</span><span class="o">.</span><span class="n">run</span><span class="p">(</span><span class="n">component_param</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">args</span><span class="p">)</span>

        <span class="c1">### start test</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">explained_variance_test</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">mean_absolute_error_test</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">mean_squared_error_test</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">mean_squared_log_error_test</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">median_absolute_error_test</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">root_mean_squared_error_test</span><span class="p">()</span></div>

<div class="viewcode-block" id="TestEvaluationRegression.assertFloatEqual"><a class="viewcode-back" href="../../../../federatedml.evaluation.test.html#federatedml.evaluation.test.evaluation_run_test.TestEvaluationRegression.assertFloatEqual">[docs]</a>    <span class="k">def</span> <span class="nf">assertFloatEqual</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">op1</span><span class="p">,</span> <span class="n">op2</span><span class="p">):</span>
        <span class="n">diff</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">abs</span><span class="p">(</span><span class="n">op1</span> <span class="o">-</span> <span class="n">op2</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">assertLess</span><span class="p">(</span><span class="n">diff</span><span class="p">,</span> <span class="mf">1e-6</span><span class="p">)</span></div>

<div class="viewcode-block" id="TestEvaluationRegression.explained_variance_test"><a class="viewcode-back" href="../../../../federatedml.evaluation.test.html#federatedml.evaluation.test.evaluation_run_test.TestEvaluationRegression.explained_variance_test">[docs]</a>    <span class="k">def</span> <span class="nf">explained_variance_test</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="n">y_true</span> <span class="o">=</span> <span class="p">[</span><span class="mi">3</span><span class="p">,</span> <span class="o">-</span><span class="mf">0.5</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">7</span><span class="p">]</span>
        <span class="n">y_pred</span> <span class="o">=</span> <span class="p">[</span><span class="mf">2.5</span><span class="p">,</span> <span class="mf">0.0</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">8</span><span class="p">]</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">assertFloatEqual</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">around</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">eval_obj</span><span class="o">.</span><span class="n">explained_variance</span><span class="p">(</span><span class="n">y_true</span><span class="p">,</span> <span class="n">y_pred</span><span class="p">),</span> <span class="mi">4</span><span class="p">),</span> <span class="mf">0.9572</span><span class="p">)</span>

        <span class="n">y_true</span> <span class="o">=</span> <span class="p">[[</span><span class="mf">0.5</span><span class="p">,</span> <span class="mi">1</span><span class="p">],</span> <span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">],</span> <span class="p">[</span><span class="mi">7</span><span class="p">,</span> <span class="o">-</span><span class="mi">6</span><span class="p">]]</span>
        <span class="n">y_pred</span> <span class="o">=</span> <span class="p">[[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span> <span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span> <span class="p">[</span><span class="mi">8</span><span class="p">,</span> <span class="o">-</span><span class="mi">5</span><span class="p">]]</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">assertFloatEqual</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">around</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">eval_obj</span><span class="o">.</span><span class="n">explained_variance</span><span class="p">(</span><span class="n">y_true</span><span class="p">,</span> <span class="n">y_pred</span><span class="p">),</span> <span class="mi">4</span><span class="p">),</span> <span class="mf">0.9839</span><span class="p">)</span></div>

<div class="viewcode-block" id="TestEvaluationRegression.mean_absolute_error_test"><a class="viewcode-back" href="../../../../federatedml.evaluation.test.html#federatedml.evaluation.test.evaluation_run_test.TestEvaluationRegression.mean_absolute_error_test">[docs]</a>    <span class="k">def</span> <span class="nf">mean_absolute_error_test</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="n">y_true</span> <span class="o">=</span> <span class="p">[</span><span class="mi">3</span><span class="p">,</span> <span class="o">-</span><span class="mf">0.5</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">7</span><span class="p">]</span>
        <span class="n">y_pred</span> <span class="o">=</span> <span class="p">[</span><span class="mf">2.5</span><span class="p">,</span> <span class="mf">0.0</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">8</span><span class="p">]</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">assertFloatEqual</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">eval_obj</span><span class="o">.</span><span class="n">mean_absolute_error</span><span class="p">(</span><span class="n">y_true</span><span class="p">,</span> <span class="n">y_pred</span><span class="p">),</span> <span class="mf">0.5</span><span class="p">)</span>

        <span class="n">y_true</span> <span class="o">=</span> <span class="p">[[</span><span class="mf">0.5</span><span class="p">,</span> <span class="mi">1</span><span class="p">],</span> <span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">],</span> <span class="p">[</span><span class="mi">7</span><span class="p">,</span> <span class="o">-</span><span class="mi">6</span><span class="p">]]</span>
        <span class="n">y_pred</span> <span class="o">=</span> <span class="p">[[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span> <span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span> <span class="p">[</span><span class="mi">8</span><span class="p">,</span> <span class="o">-</span><span class="mi">5</span><span class="p">]]</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">assertFloatEqual</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">eval_obj</span><span class="o">.</span><span class="n">mean_absolute_error</span><span class="p">(</span><span class="n">y_true</span><span class="p">,</span> <span class="n">y_pred</span><span class="p">),</span> <span class="mf">0.75</span><span class="p">)</span></div>

<div class="viewcode-block" id="TestEvaluationRegression.mean_squared_error_test"><a class="viewcode-back" href="../../../../federatedml.evaluation.test.html#federatedml.evaluation.test.evaluation_run_test.TestEvaluationRegression.mean_squared_error_test">[docs]</a>    <span class="k">def</span> <span class="nf">mean_squared_error_test</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="n">y_true</span> <span class="o">=</span> <span class="p">[</span><span class="mi">3</span><span class="p">,</span> <span class="o">-</span><span class="mf">0.5</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">7</span><span class="p">]</span>
        <span class="n">y_pred</span> <span class="o">=</span> <span class="p">[</span><span class="mf">2.5</span><span class="p">,</span> <span class="mf">0.0</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">8</span><span class="p">]</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">assertFloatEqual</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">eval_obj</span><span class="o">.</span><span class="n">mean_squared_error</span><span class="p">(</span><span class="n">y_true</span><span class="p">,</span> <span class="n">y_pred</span><span class="p">),</span> <span class="mf">0.375</span><span class="p">)</span>

        <span class="n">y_true</span> <span class="o">=</span> <span class="p">[[</span><span class="mf">0.5</span><span class="p">,</span> <span class="mi">1</span><span class="p">],</span> <span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">],</span> <span class="p">[</span><span class="mi">7</span><span class="p">,</span> <span class="o">-</span><span class="mi">6</span><span class="p">]]</span>
        <span class="n">y_pred</span> <span class="o">=</span> <span class="p">[[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span> <span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span> <span class="p">[</span><span class="mi">8</span><span class="p">,</span> <span class="o">-</span><span class="mi">5</span><span class="p">]]</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">assertFloatEqual</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">around</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">eval_obj</span><span class="o">.</span><span class="n">mean_squared_error</span><span class="p">(</span><span class="n">y_true</span><span class="p">,</span> <span class="n">y_pred</span><span class="p">),</span> <span class="mi">4</span><span class="p">),</span> <span class="mf">0.7083</span><span class="p">)</span></div>

<div class="viewcode-block" id="TestEvaluationRegression.mean_squared_log_error_test"><a class="viewcode-back" href="../../../../federatedml.evaluation.test.html#federatedml.evaluation.test.evaluation_run_test.TestEvaluationRegression.mean_squared_log_error_test">[docs]</a>    <span class="k">def</span> <span class="nf">mean_squared_log_error_test</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="n">y_true</span> <span class="o">=</span> <span class="p">[</span><span class="mi">3</span><span class="p">,</span> <span class="mi">5</span><span class="p">,</span> <span class="mf">2.5</span><span class="p">,</span> <span class="mi">7</span><span class="p">]</span>
        <span class="n">y_pred</span> <span class="o">=</span> <span class="p">[</span><span class="mf">2.5</span><span class="p">,</span> <span class="mi">5</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="mi">8</span><span class="p">]</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">assertFloatEqual</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">around</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">eval_obj</span><span class="o">.</span><span class="n">mean_squared_log_error</span><span class="p">(</span><span class="n">y_true</span><span class="p">,</span> <span class="n">y_pred</span><span class="p">),</span> <span class="mi">4</span><span class="p">),</span> <span class="mf">0.0397</span><span class="p">)</span>

        <span class="n">y_true</span> <span class="o">=</span> <span class="p">[[</span><span class="mf">0.5</span><span class="p">,</span> <span class="mi">1</span><span class="p">],</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span> <span class="p">[</span><span class="mi">7</span><span class="p">,</span> <span class="mi">6</span><span class="p">]]</span>
        <span class="n">y_pred</span> <span class="o">=</span> <span class="p">[[</span><span class="mf">0.5</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mf">2.5</span><span class="p">],</span> <span class="p">[</span><span class="mi">8</span><span class="p">,</span> <span class="mi">8</span><span class="p">]]</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">assertFloatEqual</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">around</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">eval_obj</span><span class="o">.</span><span class="n">mean_squared_log_error</span><span class="p">(</span><span class="n">y_true</span><span class="p">,</span> <span class="n">y_pred</span><span class="p">),</span> <span class="mi">4</span><span class="p">),</span> <span class="mf">0.0442</span><span class="p">)</span></div>

<div class="viewcode-block" id="TestEvaluationRegression.median_absolute_error_test"><a class="viewcode-back" href="../../../../federatedml.evaluation.test.html#federatedml.evaluation.test.evaluation_run_test.TestEvaluationRegression.median_absolute_error_test">[docs]</a>    <span class="k">def</span> <span class="nf">median_absolute_error_test</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="n">y_true</span> <span class="o">=</span> <span class="p">[</span><span class="mi">3</span><span class="p">,</span> <span class="o">-</span><span class="mf">0.5</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">7</span><span class="p">]</span>
        <span class="n">y_pred</span> <span class="o">=</span> <span class="p">[</span><span class="mf">2.5</span><span class="p">,</span> <span class="mf">0.0</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">8</span><span class="p">]</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">assertFloatEqual</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">eval_obj</span><span class="o">.</span><span class="n">median_absolute_error</span><span class="p">(</span><span class="n">y_true</span><span class="p">,</span> <span class="n">y_pred</span><span class="p">),</span> <span class="mf">0.5</span><span class="p">)</span>

        <span class="n">y_true</span> <span class="o">=</span> <span class="p">[</span><span class="mi">3</span><span class="p">,</span> <span class="o">-</span><span class="mf">0.6</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">7</span><span class="p">]</span>
        <span class="n">y_pred</span> <span class="o">=</span> <span class="p">[</span><span class="mf">2.5</span><span class="p">,</span> <span class="mf">0.0</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">8</span><span class="p">]</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">assertFloatEqual</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">eval_obj</span><span class="o">.</span><span class="n">median_absolute_error</span><span class="p">(</span><span class="n">y_true</span><span class="p">,</span> <span class="n">y_pred</span><span class="p">),</span> <span class="mf">0.55</span><span class="p">)</span></div>

<div class="viewcode-block" id="TestEvaluationRegression.root_mean_squared_error_test"><a class="viewcode-back" href="../../../../federatedml.evaluation.test.html#federatedml.evaluation.test.evaluation_run_test.TestEvaluationRegression.root_mean_squared_error_test">[docs]</a>    <span class="k">def</span> <span class="nf">root_mean_squared_error_test</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="n">y_true</span> <span class="o">=</span> <span class="p">[</span><span class="mi">3</span><span class="p">,</span> <span class="o">-</span><span class="mf">0.5</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">7</span><span class="p">]</span>
        <span class="n">y_pred</span> <span class="o">=</span> <span class="p">[</span><span class="mf">2.5</span><span class="p">,</span> <span class="mf">0.0</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">8</span><span class="p">]</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">assertFloatEqual</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">around</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">eval_obj</span><span class="o">.</span><span class="n">root_mean_squared_error</span><span class="p">(</span><span class="n">y_true</span><span class="p">,</span> <span class="n">y_pred</span><span class="p">),</span> <span class="mi">4</span><span class="p">),</span> <span class="mf">0.6124</span><span class="p">)</span>

        <span class="n">y_true</span> <span class="o">=</span> <span class="p">[[</span><span class="mf">0.5</span><span class="p">,</span> <span class="mi">1</span><span class="p">],</span> <span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">],</span> <span class="p">[</span><span class="mi">7</span><span class="p">,</span> <span class="o">-</span><span class="mi">6</span><span class="p">]]</span>
        <span class="n">y_pred</span> <span class="o">=</span> <span class="p">[[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span> <span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span> <span class="p">[</span><span class="mi">8</span><span class="p">,</span> <span class="o">-</span><span class="mi">5</span><span class="p">]]</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">assertFloatEqual</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">around</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">eval_obj</span><span class="o">.</span><span class="n">root_mean_squared_error</span><span class="p">(</span><span class="n">y_true</span><span class="p">,</span> <span class="n">y_pred</span><span class="p">),</span> <span class="mi">4</span><span class="p">),</span> <span class="mf">0.8416</span><span class="p">)</span></div>

<div class="viewcode-block" id="TestEvaluationRegression.tearDown"><a class="viewcode-back" href="../../../../federatedml.evaluation.test.html#federatedml.evaluation.test.evaluation_run_test.TestEvaluationRegression.tearDown">[docs]</a>    <span class="k">def</span> <span class="nf">tearDown</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="c1"># self.table.destroy()</span>
        <span class="k">pass</span></div></div>



<span class="k">if</span> <span class="vm">__name__</span> <span class="o">==</span> <span class="s1">&#39;__main__&#39;</span><span class="p">:</span>
    <span class="n">unittest</span><span class="o">.</span><span class="n">main</span><span class="p">()</span>
</pre></div>

           </div>
           
          </div>
          <footer>
  

  <hr/>

  <div role="contentinfo">
    <p>
        &copy; Copyright 2019, FATE_TEAM

    </p>
  </div>
  Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>. 

</footer>

        </div>
      </div>

    </section>

  </div>
  


  <script type="text/javascript">
      jQuery(function () {
          SphinxRtdTheme.Navigation.enable(true);
      });
  </script>

  
  
    
   

</body>
</html>